package gew.js;
import gew.utils.SqlUtils;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Scanner;

public class JsTemplates {

    public final static String INDICATORS_COLUMN = JsTemplates.class.getResource("indicators_column.jsgew").getPath();
    public final static String INDICATORS_GRAPH = JsTemplates.class.getResource("indicators_graph.jsgew").getPath();
    public final static String INDICATORS = JsTemplates.class.getResource("indicators.js").getPath();
    public final static String TRADE = JsTemplates.class.getResource("trade.js").getPath();
    public final static String TRADE_SUMMARY = JsTemplates.class.getResource("trade_summary.js").getPath();

    private final static HashMap<String, String> sqlTemplates = new HashMap<>();

    public static String getTemplate(String key) {
        if (!sqlTemplates.containsKey(key)) {
            initTemplate(key);
        }
        return sqlTemplates.get(key);
    }

    private static void initTemplate(String key) {
        String t = "";
        try (Scanner in = new Scanner(new FileReader(key))) {
            while (in.hasNext()) {
                t = t.concat(SqlUtils.NEW_LINE).concat(in.nextLine());
            }
        } catch (Exception e) {
            t = "";
        }
        sqlTemplates.put(key, t);
    }
}
